package com.rentalHome.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.rentalHome.domain.Room;
import com.rentalHome.domain.User;

/**
*
* @author LeeXyan
* @date 2017年2月4日 上午9:57:11
*
**/

public interface RoomRepository extends PagingAndSortingRepository<Room, Long>,JpaRepository<Room,Long> {

	@Query("select r from Room r where r.user = :user order by r.name")
	List<Room> findByUser(@Param("user")User user);
	
	@Query("select r from Room r where r.user = :user and r.isEmpty = true order by r.name")
	List<Room> findEmptyRoomByUser(@Param("user") User user);

	@Query("select r from Room r where r.name like %?1")
    List<Room> findByNames(String name);

	@Query("select r from Room r where r.name =:name")
	Room findByName(@Param("name")String name);

	@Query("select r from Room r where r.name =:name and r.isEmpty =:isEmpty and r.user = :user")
	Room findByNameAndIsEmpty(@Param("user") User user,@Param("name")String name,@Param("isEmpty")Boolean isEmpty);


	/*List<Room> findByNameLike(String name);*/

}